package com.eam.service;

import com.yy.base.common.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EquipmentStatusService {
	@Autowired
	private Dao dao;
	
	/**
	 * 获取设备
	 * @return
	 */
	public List<Map<String,Object>> getFacilities(String orgId) {
		String sql = "select f.emes_facilities_id, f.name fname, f.code fcode, ep.name pname, ep.code,"+ 
				" ep.emes_processopr_id processId,f.fancility_type"+
				" from emes_facilities f,emes_processopr ep"+
				" where f.emes_processopr_id = ep.emes_processopr_id"+
				" and f.isactive = 'Y'"+           
				" order by ep.code";
		return dao.query(sql);
	}
	
	/**
	 * 获取设备状态
	 * @param orgId
	 * @return
	 */
	public List<Map<String,Object>> getFacilitiesStatus(String orgId) {
		String sql = "select empi.emes_facilities_id,'MAINTAIN' run_status from emes_maintain_plan emp"+
				" left join emes_maintain_plan_item empi on emp.emes_maintain_plan_id=empi.emes_maintain_plan_id"+
				" where 1=1"+
				" and emp.distinguish='MAINTAIN'"+
				" and emp.status!='OK'"+
				" group by empi.emes_facilities_id"+
				" union all"+
				" select empi.emes_facilities_id,'REPAIR' run_status from emes_maintain_plan emp"+
				" left join emes_maintain_plan_item empi on emp.emes_maintain_plan_id=empi.emes_maintain_plan_id"+
				" where 1=1"+
				" and emp.distinguish='REPAIR'"+
				" and emp.status!='OK'"+
				" group by empi.emes_facilities_id";
		return dao.query(sql);
	}
}
